package com.kzj.controller;


import com.baomidou.mybatisplus.extension.api.R;
import com.kzj.common.re.Result;
import com.kzj.domain.Exercises;
import com.kzj.domain.dto.EquationDTO;
import com.kzj.domain.dto.ExercisesDTO;
import com.kzj.service.ExercisesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author kzj
 * @since 2023-11-15
 */
@CrossOrigin(origins = "/**")
@RestController
@RequestMapping("/exercises")
@Api(tags = "习题相关接口")
public class ExercisesController {
    @Autowired
    ExercisesService exercisesService;
    @PostMapping("/create")
    @ApiOperation("")
    public Result create(@RequestBody ExercisesDTO exercisesDTO){
        if(exercisesDTO.getType().equals(Exercises.ERROR_SET) )
            return exercisesService.errorSet(exercisesDTO);
        return exercisesService.create(exercisesDTO);
    }
    @PostMapping("/check")
    @ApiOperation("")
    public Result check(@RequestBody List<EquationDTO> equationDTOList, Integer practiceTime)
    {
        return exercisesService.check(equationDTOList,practiceTime);
    }
    @PostMapping("/exportDocument")
    @ApiOperation("")
    public Result exportDocument(@RequestBody ExercisesDTO exercisesDTO, HttpServletResponse  response)
    {
        return exercisesService.exportDocument(exercisesDTO,response);
    }
    @PostMapping("errorSet")
    @ApiOperation("")
    public Result errorSet(@RequestBody ExercisesDTO exercisesDTO)
    {
        return exercisesService.errorSet(exercisesDTO);
    }




}

